<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('分类列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
    <link href="/static/libs/bootstrap-treetable/bootstrap-treetable.css" rel="stylesheet">
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <div class="card card-primary card-outline card-outline-tabs mb-0">
        <div class="card-header p-0 border-bottom-0">
            <ul class="nav nav-tabs">
                <li class="nav-item" th:each="channel : ${channelList}">
                    <a class="nav-link" th:href="'/category/list.html?channelId='+${channel.channelId}" th:classappend="${channelId == channel.channelId?'active':''}" th:text="${channel.channelName}"></a>
                </li>
            </ul>
        </div>
        <div class="card-body pt-0">
            <div class="toolbar" id="toolbar" role="group">
                <a class="btn btn-success" id="btn-category-add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-info" id="expandAllBtn">
                    <i class="fa fa-exchange"></i> 展开/折叠
                </a>
            </div>
            <table id="bootstrap-tree-table"></table>
        </div>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script src="/static/libs/bootstrap-treetable/bootstrap-treetable.js"></script>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('category:add')}]];
    var editFlag = [[${@permission.hasPermi('category:edit')}]];
    var removeFlag = [[${@permission.hasPermi('category:remove')}]];
    var prefix = "/category";
    var channelId = [[${channelId}]];
    $(function() {
        var options = {
            code: "categoryId",
            parentCode: "parentId",
            expandColumn: "1",
            uniqueId: "categoryId",
            url: prefix + "/list.json?channelId=" + channelId,
            createUrl: prefix + "/add.html?parentId={id}&channelId=" + channelId,
            updateUrl: prefix + "/edit.html?id={id}",
            removeUrl: prefix + "/remove.json?id={id}",
            modalName: "分类",
            columns: [
                {
                    field: 'categoryId',
                    title: '专业Id',
                    width: '80px'
                },
                {
                    field: 'categoryName',
                    title: '专业名称',
                    align: 'left', formatter: function (value, row, index) {
                        return value + " <span style='color: #DD1144'>(id:" + row.categoryId + ")</span>"
                    }
                },
                {
                    field: 'sort',
                    title: '排序',
                    align: 'left',
                    width: '80px',
                },
                {
                    title: '操作',
                    align: 'left',
                    width: '200px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.categoryId + '\',\'' + "700px" + '\',\'' + "380px" + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.categoryId + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.categoryId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.treeTable.init(options);

        $('#btn-category-add').click(function () {
            $.modal.open("添加专业", "/category/add.html?channelId=" + channelId);
        });
        // tree表格树 展开/折叠
        $("#expandAllBtn").click(function() {
            var dataExpand = $.common.isEmpty(table.options.expandAll) ? true : table.options.expandAll;
            if (!dataExpand) {
                $.bttTable.bootstrapTreeTable('expandAll');
            } else {
                $.bttTable.bootstrapTreeTable('collapseAll');
            }
            table.options.expandAll = !dataExpand;
        });
    });
</script>
</body>
</html>